<template>
  <div class="category-list">
    <el-card>
      <template #header>
        <div class="card-header">
          <div class="card-header__titles">
            <h1 class="card-title">{{ pageTitle || '分类管理' }}</h1>
            <p v-if="pageSubtitle" class="card-subtitle">{{ pageSubtitle }}</p>
          </div>
          <el-button type="primary">
            <el-icon><Plus /></el-icon>
            创建分类
          </el-button>
        </div>
      </template>

      <el-table
        v-loading="loading"
        :data="categoryList"
        border
        stripe
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="分类名称" min-width="200" />
        <el-table-column prop="slug" label="Slug" width="150" />
        <el-table-column prop="is_active" label="状态" width="100">
          <template #default="{ row }">
            <el-tag :type="row.is_active ? 'success' : 'danger'">
              {{ row.is_active ? '激活' : '未激活' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="sort_order" label="排序" width="100" />
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="{ row }">
            <el-button type="primary" size="small">编辑</el-button>
            <el-button type="danger" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import type { Category } from '@/types'
import { usePageMeta } from '@/composables/usePageMeta'

const loading = ref(false)
const categoryList = ref<Category[]>([])
const { pageTitle, pageSubtitle } = usePageMeta()

const fetchCategories = async () => {
  loading.value = true
  try {
    // TODO: 调用 API
    categoryList.value = []
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchCategories()
})
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-lg);
}

.card-header__titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  margin: 0;
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.card-subtitle {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
}
</style>
